<?php
# http://projects:8081/cdapp-2kt-api/api/flight_diversion_get.php

include_once './_portal.php';

$begTime = isset($_GET['begTime']) ? $_GET['begTime'] : (isset($post->begTime) ? $post->begTime : (date("Y-m-d H:i:s", time() - 6 * 3600)));

// (date("Y-m-d H:i:s", time() - 60 * 3600))
// (date('Y-m-d') . ' 00:00:00')

$endTime = isset($_GET['endTime']) ? $_GET['endTime'] : (isset($post->endTime) ? $post->endTime : (date("Y-m-d H:i:s", time() + 6 * 3600)));

// (date("Y-m-d H:i:s", time() + 60 * 3600))
// (date('Y-m-d') . '23:59:59')

$fake = intval(isset($_GET['fake']) ? $_GET['fake'] : (isset($post->fake) ? $post->fake : 0));

if ($fake == 1) {
  $begTime = '2024-06-16 00:00:00';
  $endTime = '2024-06-17 23:59:59';
}

$sql = "SELECT * FROM `2kt_diversion_record` WHERE `etd` >= '{$begTime}' AND `etd` <= '{$endTime}'";

$result = exec_sql($sql);

$result = $result ? $result : [];

output(['count' => count($result), 'content' => $result, 'sql' => $sql]);

die();